﻿<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport"
        content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
    <meta name="author" content="火星科技 http://cesium.marsgis.cn ">
    <meta name="apple-touch-fullscreen" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="x5-fullscreen" content="true">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <!-- 标题及搜索关键字 -->
    <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
    <meta name="description"
        content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS" />

    <link rel="shortcut icon" type="image/x-icon" href="http://cesium.marsgis.cn/favicon.ico">
    <title>右键菜单 |Mars3D ( MarsGIS for Cesium )|三维地图| 火星科技|合肥火星科技|合肥火星科技有限公司</title>


    <!--第三方lib-->
    <script type="text/javascript" src="../lib/include-lib.js" libpath="../lib/"
        include="jquery,font-awesome,bootstrap,layer,haoutil,turf,mars3d"></script>

    <link href="css/style.css" rel="stylesheet" />
</head>

<body class="dark">
    <!--加载前进行操作提示，优化用户体验-->
    <div id="mask" class="signmask" onclick="removeMask()"></div>

    <div id="cesiumContainer" class="mars3d-container"></div>


    <!-- 面板 -->
    <div class="infoview">
        1、默认右键菜单通过 viewer.mars.contextmenuItems 属性进行指定<br />
        2、矢量数据的右键菜单通过 entity.contextmenuItems 属性进行指定<br />
    </div>


    <!-- 涉及mars的在线服务地址统一配置入口 -->
    <script type="text/javascript" src="config/marsUrl.js"></script>



    <script type="text/javascript">
        $(document).ready(function () {
            if (!mars3d.util.webglreport()) {
                alert('系统检测到您使用的浏览器不支持WebGL功能');
                layer.open({
                    type: 1,
                    title: "当前浏览器不支持WebGL功能",
                    closeBtn: 0,
                    shadeClose: false,
                    resize: false,
                    area: ['600px', '200px'], //宽高
                    content: '<div style="margin: 20px;"><h3>系统检测到您使用的浏览器不支持WebGL功能！</h3>  <p>1、请您检查浏览器版本，安装使用最新版chrome、火狐或IE11以上浏览器！</p> <p>2、WebGL支持取决于GPU支持，请保证客户端电脑已安装显卡驱动程序！</p></div>'
                });
            }

            initMap();
        });

        function removeMask() {
            $("#mask").remove();
        }


        var viewer;
        //初始化地图
        function initMap() {
            //url传参，一个系统动态使用不同配置
            var configfile = haoutil.system.getRequestByName("config", "config/config.json");

            mars3d.createMap({
                id: 'cesiumContainer',
                url: configfile,
                center: { "y": 31.808241, "x": 117.224601, "z": 4071.32, "heading": 356.7, "pitch": -61, "roll": 360 },
                success: function (_viewer, jsondata) {//地图成功加载完成后执行
                    viewer = _viewer;

                    setTimeout(removeMask, 3000);
                    initWork();
                }
            });
        }


        //当前页面业务相关
        function initWork() {

            var defaultContextmenuItems = [
                {
                    text: '显示此处经纬度',
                    iconCls: 'fa fa-info-circle',
                    callback: function (e) {
                        var mpt = mars3d.point.formatPosition(e.position);

                        var inhtml = "经度：" + mpt.x + " , 纬度：" + mpt.y + "<br/>高程：" + mpt.z;
                        haoutil.alert(inhtml, '位置信息');
                    }
                },
                {
                    text: '开启深度监测',
                    iconCls: 'fa fa-eye-slash',
                    visible: function () {
                        return !viewer.scene.globe.depthTestAgainstTerrain
                    },
                    callback: function (e) {
                        viewer.scene.globe.depthTestAgainstTerrain = true;
                    }
                },
                {
                    text: '关闭深度监测',
                    iconCls: 'fa fa-eye',
                    visible: function () {
                        return viewer.scene.globe.depthTestAgainstTerrain
                    },
                    callback: function (e) {
                        viewer.scene.globe.depthTestAgainstTerrain = false;
                    }
                },
                {
                    text: '视角切换',
                    iconCls: 'fa fa-street-view',
                    children: [
                        {
                            text: '第一视角站到此处',
                            iconCls: 'fa fa-street-view',
                            callback: function (e) {

                                viewer.camera.flyTo({
                                    destination: mars3d.point.addPositionsHeight(e.position, 10), //升高10米
                                    orientation: {
                                        heading: Cesium.Math.toRadians(0),    //绕垂直于地心的轴旋转
                                        pitch: Cesium.Math.toRadians(10),      //绕纬度线旋转
                                        roll: Cesium.Math.toRadians(0)        //绕经度线旋转
                                    },
                                });
                            }
                        },
                        {
                            text: '开启键盘漫游',
                            iconCls: 'fa fa-keyboard-o',
                            visible: function (e) {
                                return !viewer.mars.keyboardRoam.enable
                            },
                            callback: function (e) {
                                viewer.mars.keyboardRoam.enable = true;
                            }
                        },
                        {
                            text: '关闭键盘漫游',
                            iconCls: 'fa fa-keyboard-o',
                            visible: function (e) {
                                return viewer.mars.keyboardRoam.enable
                            },
                            callback: function (e) {
                                viewer.mars.keyboardRoam.enable = false;
                            }
                        },
                        {
                            text: '取消锁定',
                            iconCls: 'fa fa-unlock-alt',
                            visible: function (e) {
                                return viewer.trackedEntity != undefined
                            },
                            callback: function (e) {
                                viewer.trackedEntity = undefined;
                            }
                        },
                    ]
                }
            ]  
            viewer.mars.contextmenuItems = defaultContextmenuItems;


            // viewer.mars.contextmenu.close()   //外部调用关闭菜单
            // viewer.mars.contextmenu.resetDefault();  //在设置后,可以还原为框架内部默认的菜单



            var entityContextmenuItems = [
                {
                    text: '删除对象',
                    iconCls: 'fa fa-trash-o',
                    callback: function (e) {
                        var entity = e.target;
                        if (entity)
                            viewer.entities.remove(entity);
                    }
                }
            ]

            var pointEntity = viewer.entities.add({
                name: "点",
                position: Cesium.Cartesian3.fromDegrees(117.22193, 31.823638, 43.48),
                billboard: {
                    image: 'img/marker/mark3.png',
                    scale: 1,
                    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                },
                contextmenuItems: entityContextmenuItems
            });

            var lineEntity = viewer.entities.add({
                name: "线",
                polyline: {
                    positions: Cesium.Cartesian3.fromDegreesArrayHeights([
                        117.210308, 31.82165, 39.61,
                        117.217186, 31.819723, 35,
                        117.216931, 31.828351, 38.79,
                        117.214205, 31.828521, 41.01,
                        117.214378, 31.825595, 32.42
                    ]),
                    width: 7,
                    material: Cesium.Color.YELLOW.withAlpha(0.5),
                    clampToGround: true
                },
                contextmenuItems: entityContextmenuItems
            });


            var polyEntity = viewer.entities.add({
                name: "面",
                polygon: {
                    hierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights([
                        117.220448, 31.834688, 40.72,
                        117.226041, 31.834192, 40.93,
                        117.226094, 31.831935, 48.08,
                        117.220457, 31.831917, 46.88,
                        117.220448, 31.834688, 40.72
                    ])),
                    width: 5,
                    material: Cesium.Color.YELLOW.withAlpha(0.3),
                    classificationType: Cesium.ClassificationType.BOTH
                },
                contextmenuItems: entityContextmenuItems
            });



            var layerWork = mars3d.layer.createLayer(viewer,{
                "name": "教学楼",
                "type": "3dtiles",
                "url": serverURL_3dtiles + "/bim-daxue/tileset.json", //定义在 config\marsUrl.js 
                "scale":3,
                "offset": { "x":  117.228508 , "y": 31.82915, "z": 53, "heading": 1.9 },
                "maximumScreenSpaceError": 16,
                "maximumMemoryUsage": 1024,
                "scenetree": "scenetree.json",
                "showClickFeature": true,
                "popup": "all",
                "visible": true,
                "contextmenuItems": [
                    {
                        text: '删除模型',
                        iconCls: 'fa fa-trash-o',
                        callback: function (e) {
                            layerWork.remove();
                        }
                    }
                ]
            });

             


        }




    </script>
</body>

</html>